#pragma once
#include <functional>

int mymath(int x,int y,char op);

class Task
{
    using func_t = function<int(int,int,char)>;
public:
    Task()
    {}

    Task(int x, int y, char op, func_t callback = mymath)
    :_x(x),_y(y),_op(op),_callback(callback)
    {}

    string operator()()
    {
        int result = _callback(_x,_y,_op);
        char buffer[1024];
        snprintf(buffer,sizeof buffer, "%d %c %d = %d",_x,_op,_y,result);
        return buffer;
    }

    string to_TaskString()
    {
        char buffer[1024];
        snprintf(buffer,sizeof buffer, "%d %c %d = ?",_x,_op,_y);
        return buffer;
    }

private:
    int _x;
    int _y;
    char _op;
    func_t _callback;
};

string oper = "+-*/%";

int mymath(int x, int y, char op)
{
    switch(op)
    {
        case '+':   return x+y; break;
        case '-':   return x-y; break;
        case '*':   return x*y; break;
        case '/':   
        {
            if(y == 0)
            {
                cerr << "div zero error!" << endl;
                return -1;
            }
            else
            {
                return x/y;
            }
            break;
        }
        case '%': 
        {
            if(y == 0)
            {
                cerr << "mod zero error!" << endl;
                return -1;
            }
            else 
            {
                return x%y; 
            }
            break;
        }
    }
}